package com.cby.widget.sample.bubblenavigation

import android.graphics.Typeface
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager.widget.ViewPager
import com.cby.widget.lib.bubblenavigation.BubbleNavigationLinearView
import com.cby.widget.sample.R
import com.cby.widget.sample.fragments.ScreenSlidePageFragment
import java.util.ArrayList

/**
 * @description: BubbleNavBottomBarActivity
 *
 * @author ChenBaoyang
 * @date 2021/10/16 16:23
 */
class BubbleNavBottomBarActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_bubble_nav_bottom_bar)

        val fragList: ArrayList<ScreenSlidePageFragment> = ArrayList<ScreenSlidePageFragment>()
        fragList.add(
            ScreenSlidePageFragment.newInstance(
                getString(R.string.home),
                R.color.red_inactive
            )
        )
        fragList.add(
            ScreenSlidePageFragment.newInstance(
                getString(R.string.search),
                R.color.blue_inactive
            )
        )
        fragList.add(
            ScreenSlidePageFragment.newInstance(
                getString(R.string.likes),
                R.color.blue_grey_inactive
            )
        )
        fragList.add(
            ScreenSlidePageFragment.newInstance(
                getString(R.string.notification),
                R.color.green_inactive
            )
        )
        fragList.add(
            ScreenSlidePageFragment.newInstance(
                getString(R.string.profile),
                R.color.purple_inactive
            )
        )
        val pagerAdapter = ScreenSlidePagerAdapter(
            fragList,
            supportFragmentManager
        )

        val bubbleNavigationLinearView: BubbleNavigationLinearView =
            findViewById(R.id.bottom_navigation_view_linear)
        bubbleNavigationLinearView.setTypeface(Typeface.createFromAsset(assets, "rubik.ttf"))

        bubbleNavigationLinearView.setBadgeValue(0, "40")
        bubbleNavigationLinearView.setBadgeValue(1, null) //invisible badge

        bubbleNavigationLinearView.setBadgeValue(2, "7")
        bubbleNavigationLinearView.setBadgeValue(3, "2")
        bubbleNavigationLinearView.setBadgeValue(4, "") //empty badge


        val viewPager: ViewPager = findViewById(R.id.view_pager)
        viewPager.adapter = pagerAdapter
        viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(i: Int, v: Float, i1: Int) {}
            override fun onPageSelected(i: Int) {
                bubbleNavigationLinearView.setCurrentActiveItem(i)
            }

            override fun onPageScrollStateChanged(i: Int) {}
        })

        bubbleNavigationLinearView.setNavigationChangeListener { view, position ->
            viewPager.setCurrentItem(
                position,
                true
            )
        }
    }
}